package com.demo.example.proxy.cglib;

import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;
import java.util.Date;

public class LogInterceptor implements MethodInterceptor {
    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        before(method.getName());
        Object result = methodProxy.invokeSuper(o, objects);
        after(method.getName());
        return result;
    }

    private void before(String methodName) {
        System.out.printf("[%s] 准备开始执行%s方法%n", new Date(), methodName);
    }
    private void after(String methodName) {
        System.out.printf("[%s] %s方法方法执行结束%n", new Date(), methodName);
    }
}
